<template>
	<view>
		<view class="page-head">
			<view class="course-tab flex-box">
				<view v-for="(item, index) in courseTabList" :class="{ active: courseTabCurrent === index }" @click="courseTabClick(index)" class="tab-item">{{ item }}</view>
			</view>
		</view>
		<view class="container">
			<block v-if="courseTabCurrent == 0">
				<view class="total1 fs26 p40">
					<view class="flex-box mb10">
						<view class="col-black">学习总时长：</view>
						<view class="col-red">{{viewTime}}</view>
					</view>
					<view>
						学习了
						<text class="col-red">{{viewCount}}</text>
						个音视频
					</view>
				</view>
				<!--  -->
				<view class="course-list2 plr30">
					<navigator :url="'/pages/course_video_detail/course_video_detail?course_id='+item.course.id" class="nav-course flex-box ptb30" hover-class="none" v-for="(item, index) in courseLists">
						<!-- <view class="time-long">00:08:00</view> -->
						<image class="img-course mr20" :src="item.course.thumb_image" mode="aspectFill"></image>
						<view class="flex-1">
							<view class="m-ellipsis fs26 col-0 mb10">{{ item.course.name }}</view>
							<view class="m-ellipsis fs22 col-6 mb30">{{ item.course.description }}</view>
							<view class="flex-box">
								<image class="icon1 mr10" v-if="item.course.type == 1" src="/static/icon/icon_tv.png" mode="aspectFit"></image>
								<image class="icon1 mr10" v-if="item.course.type == 2" src="/static/icon/icon_tv.png" mode="aspectFit"></image>
								<image class="icon1 mr10" v-if="item.course.type == 3" src="/static/icon/icon_tv.png" mode="aspectFit"></image>
							</view>
						</view>
					</navigator>
					<view class="g-btn3-wrap">
						<view class="g-btn3" :class="{nomore: courseListsMore.nomore == true || courseListsMore.loading == true}" @click="fetchStudyLists">{{courseListsMore.text}}</view>
					</view>
				</view>
			</block>
			<block v-if="courseTabCurrent == 1">
				<view class="total1 fs26 p40 col-black">
					参加课程报名{{offlineCount}}次
				</view>
				<view class="offline_course p30">
					<navigator class="item mb40" :url="'/pages/offline_course_detail/offline_course_detail?course_id='+item.offline.id" hover-class="none" v-for="(item,index) in offlineCourseLists">
						<view class="img-box pr mb25">
							<image :src="item.course_image" mode="aspectFill"></image>
							<!-- <view class="tc fs20 col-f" :class="(item.state==1 || item.state==2)? 'status1' : 'status2'">{{item.state_text}}</view> -->
						</view>
						<view class="mb25 fs28 col-black fwb m-ellipsis">{{item.course_name}}</view>
						<view class="flex-box mb25">
							<view class="g-price1 flex-1 fwb">{{item.course_salesprice}}</view>
							<!-- <image class="icon1 mr10" src="/static/icon/icon_already.png" mode="aspectFit"></image> -->
							<!-- <view class="fs22 col-9">已报名{{item.enroll_count}}人 | 剩余{{item.left_count}}人</view> -->
						</view>
						<view class="flex-box mb25">
							<image class="icon1 mr20" src="/static/icon/icon_time1.png" mode="aspectFit"></image>
							<view class="fs26 col-3 flex-1">开课时间：{{item.course_start_time_text}} 至 {{item.course_end_time_text}}</view>
						</view>
						<view class="flex-box">
							<image class="icon1 mr20" src="/static/icon/icon_location.png" mode="aspectFit"></image>
							<view class="fs26 col-3 flex-1">开课地点：{{item.course_address}}</view>
						</view>
					</navigator>
					<view class="g-btn3-wrap">
						<view class="g-btn3" :class="{nomore: offlineCourseListsMore.nomore == true || offlineCourseListsMore.loading == true}" @click="fetchOfflineLists">{{offlineCourseListsMore.text}}</view>
					</view>
				</view>
			</block>
		</view>
	</view>
</template>

<script>
	const util = require('@/xiluedu/util.js');
export default {
	data() {
		return {
			courseTabList: ['线上学习', '线下学习'],
			courseTabCurrent: 0,
			viewTime:'0',
			viewCount:0,
			courseLists:[],
			courseListsMore:{page:1},
			
			offlineCount:0,
			offlineCourseLists:[],
			offlineCourseListsMore:{page:1},
		};
	},
	onLoad(){
		this.fetchStudyLists();
		this.fetchOfflineLists();
	},
	methods: {
		courseTabClick(i) {
			this.courseTabCurrent = i;
		},
		fetchStudyLists(){
			util.fetch(this, 'xiluedu.user/study', {pagesize:10}, 'courseListsMore', 'courseLists', 'data', list=>{
				this.viewTime = list.view_time;
				this.viewCount = list.view_count;
			});
		},
		fetchOfflineLists(){
			util.fetch(this, 'xiluedu.user/study_offline', {pagesize:10}, 'offlineCourseListsMore', 'offlineCourseLists', 'data', list=>{
				this.offlineCount = list.offline_count;
			});
		},
	}
};
</script>

<style scoped>
.container {
	padding-top: 90rpx;
}
.course-tab {
	background-color: #fff;
	height: 90rpx;
	border-bottom: 1rpx solid #e1e1e1;
	justify-content: space-around;
}
.course-tab .tab-item {
	position: relative;
	line-height: 90rpx;
	text-align: center;
	font-size: 28rpx;
	font-weight: 500;
	color: #333;
}
.course-tab .tab-item.active {
	color: var(--red);
}
.course-tab .tab-item.active:before {
	position: absolute;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	content: '';
	width: 100%;
	height: 4rpx;
	background: var(--red);
	border-radius: 2rpx;
}
.total1 {
	border-bottom: 1rpx solid #e1e1e1;
}

.course-list2 .img-course {
	display: block;
	width: 280rpx;
	height: 160rpx;
	border-radius: 10rpx;
}
.course-list2 .nav-course + .nav-course {
	border-top: 1rpx solid var(--border);
}


.offline_course {
	background-color: #fff;
	border-radius: 10rpx 10rpx 0 0;
}
.offline_course .item {
	width: 100%;
}
.offline_course .img-box {
	width: 100%;
	height: 360rpx;
	border-radius: 10rpx;
	overflow: hidden;
}
.offline_course .img-box image {
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 10rpx;
}
.offline_course .img-box .status1 {
	position: absolute;
	top: 0;
	left: 0;
	padding:0 10rpx;
	height: 34rpx;
	border-radius: 10rpx 0 0 0;
	line-height: 34rpx;
	background: linear-gradient(90deg, #d7aa4e, #f4c972);
}
.offline_course .img-box .status2 {
	position: absolute;
	top: 0;
	left: 0;
	padding:0 10rpx;
	height: 34rpx;
	border-radius: 10rpx 0 0 0;
	line-height: 34rpx;
	background: #d8d8d8;
}
.offline_course .icon1 {
	display: block;
	width: 30rpx;
	height: 30rpx;
}
@media only screen and (min-width: 800px){
	.offline_course{
		border-radius: 30rpx 30rpx 0 0;
	}
	.offline_course .img-box{
		height: 800rpx;
		border-radius: 30rpx;
	}
	.offline_course .status1{
		padding-left: 20rpx!important;
	}
	.offline_course .status2{
		padding-left: 20rpx!important;
	}

}
</style>
